import 'package:casdon/core/logger/log.dart';
import 'package:casdon/core/network/business_exception.dart';
import 'package:casdon/modules/login/data/api/validate_otp_api.dart';
import 'package:casdon/modules/login/data/api/valide_code_type.dart';
import 'package:casdon/modules/login/data/repository/auth_repository.dart';

class VerifyOtpUsecase {
  final AuthRepository repository;
  const VerifyOtpUsecase(this.repository);

  Future<bool> execute(String account, String code, ValideCodeType type) async {
    if (code.length != 6) throw Exception("验证码格式错误");
    try {
      final ret = await repository.vierfyCode(
        RequestValidateOtpApi(userName: account, code: code, type: type.value),
      );
      return ret.result;
    } on BusinessException {
      rethrow;
    } catch (e) {
      throw Exception("发送短信失败");
    }
  }
}
